<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="出行单Id" prop="travelListId">
      <el-input v-model="dataForm.travelListId" placeholder="出行单Id"></el-input>
    </el-form-item>
    <el-form-item label="出行人Id" prop="travelOrderUserId">
      <el-input v-model="dataForm.travelOrderUserId" placeholder="出行人Id"></el-input>
    </el-form-item>
    <el-form-item label="出行人抵达状态【0 未抵达 1 抵达 】" prop="arriveStatus">
      <el-input v-model="dataForm.arriveStatus" placeholder="出行人抵达状态【0 未抵达 1 抵达 】"></el-input>
    </el-form-item>
    <el-form-item label="出行人姓名" prop="travelOrderUserTrueName">
      <el-input v-model="dataForm.travelOrderUserTrueName" placeholder="出行人姓名"></el-input>
    </el-form-item>
    <el-form-item label="出行人电话" prop="travelOrderUserMobile">
      <el-input v-model="dataForm.travelOrderUserMobile" placeholder="出行人电话"></el-input>
    </el-form-item>
    <el-form-item label="是否删除【1 删除 0 未删除】" prop="isDeleted">
      <el-input v-model="dataForm.isDeleted" placeholder="是否删除【1 删除 0 未删除】"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="出行order状态【0 预订  1 出行中  2 已抵达  3 出行单已取消  4 取消Order直接删除】" prop="orderStatus">
      <el-input v-model="dataForm.orderStatus" placeholder="出行order状态【0 预订  1 出行中  2 已抵达  3 出行单已取消  4 取消Order直接删除】"></el-input>
    </el-form-item>
    <el-form-item label="发单人Id" prop="travelListUserId">
      <el-input v-model="dataForm.travelListUserId" placeholder="发单人Id"></el-input>
    </el-form-item>
    <el-form-item label="发单人姓名" prop="travelListUserTrueName">
      <el-input v-model="dataForm.travelListUserTrueName" placeholder="发单人姓名"></el-input>
    </el-form-item>
    <el-form-item label="发单人电话" prop="travelListUserMobile">
      <el-input v-model="dataForm.travelListUserMobile" placeholder="发单人电话"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          travelListId: '',
          travelOrderUserId: '',
          arriveStatus: '',
          travelOrderUserTrueName: '',
          travelOrderUserMobile: '',
          isDeleted: '',
          createTime: '',
          updateTime: '',
          orderStatus: '',
          travelListUserId: '',
          travelListUserTrueName: '',
          travelListUserMobile: ''
        },
        dataRule: {
          travelListId: [
            { required: true, message: '出行单Id不能为空', trigger: 'blur' }
          ],
          travelOrderUserId: [
            { required: true, message: '出行人Id不能为空', trigger: 'blur' }
          ],
          arriveStatus: [
            { required: true, message: '出行人抵达状态【0 未抵达 1 抵达 】不能为空', trigger: 'blur' }
          ],
          travelOrderUserTrueName: [
            { required: true, message: '出行人姓名不能为空', trigger: 'blur' }
          ],
          travelOrderUserMobile: [
            { required: true, message: '出行人电话不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除【1 删除 0 未删除】不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '出行order状态【0 预订  1 出行中  2 已抵达  3 出行单已取消  4 取消Order直接删除】不能为空', trigger: 'blur' }
          ],
          travelListUserId: [
            { required: true, message: '发单人Id不能为空', trigger: 'blur' }
          ],
          travelListUserTrueName: [
            { required: true, message: '发单人姓名不能为空', trigger: 'blur' }
          ],
          travelListUserMobile: [
            { required: true, message: '发单人电话不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/travelorder/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.travelListId = data.travelOrder.travelListId
                this.dataForm.travelOrderUserId = data.travelOrder.travelOrderUserId
                this.dataForm.arriveStatus = data.travelOrder.arriveStatus
                this.dataForm.travelOrderUserTrueName = data.travelOrder.travelOrderUserTrueName
                this.dataForm.travelOrderUserMobile = data.travelOrder.travelOrderUserMobile
                this.dataForm.isDeleted = data.travelOrder.isDeleted
                this.dataForm.createTime = data.travelOrder.createTime
                this.dataForm.updateTime = data.travelOrder.updateTime
                this.dataForm.orderStatus = data.travelOrder.orderStatus
                this.dataForm.travelListUserId = data.travelOrder.travelListUserId
                this.dataForm.travelListUserTrueName = data.travelOrder.travelListUserTrueName
                this.dataForm.travelListUserMobile = data.travelOrder.travelListUserMobile
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/travelorder/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'travelListId': this.dataForm.travelListId,
                'travelOrderUserId': this.dataForm.travelOrderUserId,
                'arriveStatus': this.dataForm.arriveStatus,
                'travelOrderUserTrueName': this.dataForm.travelOrderUserTrueName,
                'travelOrderUserMobile': this.dataForm.travelOrderUserMobile,
                'isDeleted': this.dataForm.isDeleted,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'orderStatus': this.dataForm.orderStatus,
                'travelListUserId': this.dataForm.travelListUserId,
                'travelListUserTrueName': this.dataForm.travelListUserTrueName,
                'travelListUserMobile': this.dataForm.travelListUserMobile
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
